<?php $this->load->view('sys_header');?>
<script type="text/javascript">
lin.ns('lin.admin.message');
    $(function(){
        lin.admin.message.searchform = $('#info_searchform').form();
        lin.admin.message.editrow = undefined;
        $('#info_list').datagrid({

            url:'<?php echo made_admin_url('message/rows');?>',
            idField:'id',
            fitColumns:true,
            border:false,
            pagination:true,
            pageSize:10,
            pageList:[10,20,30,40,50,60,70,80,90,100],
            nowrap: false,
            striped: true,
            style:"background: #fff",
            loadMsg : '数据载入中......',
            sortName:'id',
            sortOrder:'desc',

            onLoadError : function() {

                alert('数据加载失败!');

            },
            frozenColumns:[[
                {field:'id',checkbox:true}
            ]],
            columns:[[
                {field:'showid',title:'ID',align:'center',width:30},
                {field:'txt_Name',title:'姓名',width:50},
                {field:'dropSex',title:'性别',width:30,align:'center',
                    formatter:function(value){
                        if (value == 'M')
                        {
                            return '先生';
                        }
                        else if(value == 'F')
                        {
                            return '女士';
                        }

                    }
                },
                {field:'txt_Email',title:'邮件地址',width:80,align:'center'},
                {field:'txt_Title',title:'主题',width:fixWidth(0.3)},
                {field:'reply',title:'是否回复',width:50,align:'center',
                    formatter:function(value){
                        if (value != null)
                        {
                            return '已回复';
                        }
                        else
                        {
                            return '<span class=red>未回复</span>';
                        }

                    }
                },
                {field:'isshow',title:'审核',width:50,align:'center',
                    formatter:function(value){
                        if (value == 1)
                        {
                            return '已审核';
                        }
                        else
                        {
                            return '<span class=red>未审核</span>';
                        }

                    },
                    editor:{
                        "type":"checkbox",
                                "options":{
                                "on":'1',
                                "off":'0'
                        }
                    }
                },
                {field:'time',title:'添加时间',width:100}


            ]],

            toolbar:[{
                text:"回复",
                iconCls:'icon-edit',
                handler:function(){
                    var rows = $('#info_list').datagrid('getSelections');
                    if(rows.length == 1)
                    {
                        //跳转到回复页面
                        window.location.href = '<?php echo made_admin_url('message/reply?id=');?>'+rows[0]['id'];
                        return false; //hack ie6跳转无效

                    }else if(rows.length == 0)
                    {
                        lin.msg('没有选择数据！','error');
                        return;
                    }else if(rows.length > 1)
                    {
                        lin.msg('一次只能回复一条留言！','error');
                        return;
                    }
                }
            },'-',{
                text:"删除",
                iconCls:'icon-remove',
                handler:function(){
                    var rows = $('#info_list').datagrid('getSelections');
                    if(rows.length > 0)
                    {
                        $.messager.confirm('请确认','您确定要删除当前所选择的记录吗？',function(r){
                           if(r)
                           {

                               var id_arr = [];
                               for( var i = 0 ; i < rows.length; i++){
                                   id_arr.push(rows[i].id);
                               }

                               $.ajax({
                                   type:'post',
                                   url:'<?php echo made_admin_url('message/del');?>',
                                   data:{id_arr:id_arr.join(',')},
                                   dataType:"json",
                                   success:function(r){
                                       if(r && r.success)
                                       {
                                           lin.msg('删除成功','message');
                                           $('#info_list').datagrid('load');
                                           $('#info_list').datagrid('unselectAll');    //取消所有选择

                                       }

                                   }

                               });
                           }
                            else
                           {

                           }
                        });
                    }
                    else
                    {
                        lin.msg('请选择要删除的记录！','error');
                    }
                }
            },'-',{
                text:"撤销",
                iconCls:'icon-redo',
                handler:function(){
                    lin.admin.message.editrow = undefined;
                    $('#info_list').datagrid('rejectChanges');  //回滚编辑前状态
                    $('#info_list').datagrid('unselectAll');    //取消所有选择
                    $('#info_list').datagrid('load');    //刷新
                }
            },'-',{
                text:"保存",
                iconCls:'icon-save',
                handler:function(){
                    $('#info_list').datagrid('endEdit',lin.admin.message.editrow);
                }
            },'-'

            ],

        onAfterEdit:function(rowIndex, rowData, changes){
            var inserted =  $('#info_list').datagrid('getChanges','inserted');
            var updated =  $('#info_list').datagrid('getChanges','updated');

            var url = '';
            //if(inserted.length > 0)
           // {
           //     url = '<?php echo made_admin_url('message/insert');?>';
           // }
            if(updated.length > 0)
            {
                url = '<?php echo made_admin_url('message/edit');?>';
            }

            //提交数据到后台
            $.ajax({
                type:"post",
                dataType: "json",//返回json格式的数据
                url: url,
                data: rowData,
                success: function(r){
                     if(r && r.success)
                     {
                         $('#info_list').datagrid('acceptChanges');
                         $('#info_list').datagrid('load'); //刷新数据
                         lin.msg(r.msg,'info');

                     }
                    else
                     {
                         $('#info_list').datagrid('rejectChanges');
                         lin.msg(r.msg,'error');
                         $('#info_list').datagrid('load');    //刷新
                     }
                    lin.admin.info.editrow = undefined;
                    $('#info_list').datagrid('unselectAll');    //取消所有选择
                }
            });

        },

        onDblClickRow:function(rowIndex, rowData){
             if(lin.admin.message.editrow != undefined)
             {
                 $('#info_list').datagrid('endEdit',lin.admin.message.editrow);
             }
             else
             {
                 $('#info_list').datagrid('beginEdit',rowIndex);
                 lin.admin.message.editrow = rowIndex;
             }
        },
        onSortColumn:function(){
            //排序操作
        }



        });
    });
    function fixWidth(percent)
    {
        return document.body.clientWidth * percent ; //这里你可以自己做调整
    }

    info_search = function(){
        $('#info_list').datagrid('load',lin.serializeObject(lin.admin.message.searchform));
    }
</script>



<div class="nav">
    <h2><a href="<?php echo made_admin_url('main/mainfra');?>">TAYCMS后台管理</a> >  <a href="<?php echo made_admin_url('message');?>">客户留言管理</a> </h2>
</div>


<div class="search">
    <h1></h1>
    <div class="ml"></div>

    <div>

        <form id="info_searchform">
            <table width="300" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="60" align="right" >关键词：</td>
                    <td align="left"  ><input name="keywords" type="text" class="keywords inputborder" /></td>

                    <td width="50" align="left">
                        <input name="search_submit" type="button" value="查询" class="sh_btn" onclick="info_search();" />
                    </td>
                </tr>
            </table>
        </form>

    </div>

</div>


<div class="list_warp">

    <div class="content_list" style=" border: 1px #ccc solid; ">
        <table id="info_list" ></table>
    </div>


</div>





<?php $this->load->view('sys_footer');?>